package com.gem.service.impl;

import com.gem.entity.Order;
import com.gem.entity.OrderDetails;
import com.gem.mapper.OrderDetailsMapper;
import com.gem.mapper.OrderMapper;
import com.gem.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhang
 * @date 2020/10/4 15:43
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;
    @Autowired
    OrderDetailsMapper orderDetailsMapper;

    @Override
    public void addOrder(Order order, List<OrderDetails> orderDetails) {
        orderMapper.insertOrder(order);
        for (OrderDetails detail : orderDetails) {
            orderDetailsMapper.insertOrderDetails(detail);
        }
    }

    @Override
    public List<Order> findOrderByCustomerId(int id) {
        return orderMapper.selectOrderByCustomerId(id);
    }

    @Override
    public Order findOrderById(int id) {
        return orderMapper.selectOrderById(id);
    }
}
